//
//  queryDataQATableCellView.m
//  cocoapodText
//
//  Created by apple on 16/10/19.
//  Copyright © 2016年 apple. All rights reserved.
//


#import "ShiPei.h"
#import <Foundation/Foundation.h>
#import "queryDataQATableCellView.h"

@interface queryDataQATableCellView()
@end

@implementation queryDataQATableCellView
/**
 *  初始化视图属性
 *
 *  @param frame 视图frame
 *
 *  @return self
 */
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        //定制View
        self.backgroundColor = [UIColor clearColor];
        self.userInteractionEnabled = YES; //设置为NO后，不再响应touch方法
        self.multipleTouchEnabled = YES;
        //控制子视图不能超出父视图的范围
        self.clipsToBounds = YES;
        //添加子视图
        [self subView];
    }
    return self;
}

//子视图懒加载
-(void)subView{
    UIView *allBackView=[[UIView alloc]initWithFrame:[ShiPei CGRectMakeScale:0 :0 :630 :35]];
    [self addSubview:allBackView];
    [allBackView setUserInteractionEnabled:YES];
    [allBackView setBackgroundColor:[UIColor clearColor]];
    self.allBackView=allBackView;
    //名称150
    UILabel *itemName=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:0 :0 :75 :35]];
    [allBackView addSubview:itemName];
    [itemName setText:@""];
    [itemName setTextColor:FUIColorFromRGB(0x333333)];
    [itemName setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:23]]];
    [itemName setTextAlignment:NSTextAlignmentCenter];
    self.itemName=itemName;
    //可变列表格
}

-(void)setName:(NSString *)name{
    [self.itemName setText:name];
}

-(void)setInfos:(NSMutableArray *)infos{
    //设置frame
    CGRect frame=self.allBackView.frame;
    CGFloat ContentWidth=[ShiPei CGFloatMakeScale:[infos count]*100+75];
    frame.size.width=ContentWidth;
    [self.allBackView setFrame:frame];
    //设置数据
    [self variableColumnTextView:infos];
}

-(void)variableColumnTextView:(NSMutableArray *)infos{
    [self.allBackView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self.allBackView addSubview: self.itemName];
    CGFloat left=75,labelW=100,labelH=35;
    for (int i=0; i<[infos count]; i++) {
        UILabel *temShowLabel=[[UILabel alloc]initWithFrame:[ShiPei CGRectMakeScale:left+labelW*i :0 :labelW :labelH]];
        [self.allBackView addSubview:temShowLabel];
        NSString *temShowText=[infos objectAtIndex:i];
        temShowText=[CommonTool keepDecimal:temShowText];
        [temShowLabel setText:temShowText];
        [temShowLabel setTextColor:FUIColorFromRGB(0x333333)];
        [temShowLabel setFont:[UIFont boldSystemFontOfSize:[ShiPei CGFloatMakeFontScaleWithPX:23]]];
        [temShowLabel setTextAlignment:NSTextAlignmentCenter];
    }
}

@end
